package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.TaxBillSimple;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lianhong
 * @since 2022/4/15
 */
@Repository
public class TaxBillSimpleDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String insertTaxBillSimpleSql = "INSERT INTO sw_tax_bill_simple (taxHeadSeqNo) VALUES (:taxHeadSeqNo)";

    public void save(List<TaxBillSimple> simpleList) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(simpleList);
        namedParameterJdbcTemplate.batchUpdate(insertTaxBillSimpleSql, batch);
    }

    private String deleteTaxBillSimpleSql = "DELETE FROM sw_tax_bill_simple WHERE taxHeadSeqNo IN (:taxHeadSeqNos)";

    public void deleteBy(List<String> taxHeadSeqNos) {
        Map<String, Object> params = new HashMap<>();
        params.put("taxHeadSeqNos", taxHeadSeqNos);
        namedParameterJdbcTemplate.update(this.deleteTaxBillSimpleSql, params);
    }
}
